Skip to content

fix(mcp): Stop reporting rejected client requests as Sentry issues - #2282

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/mcp-transport-client-rejections
Open

sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/mcp-transport-client-rejections

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Fixes MCP-SERVER-GFB

Not Acceptable: Client must accept both application/json and text/event-stream is the MCP SDK's Streamable HTTP transport answering a malformed client request with a 406. The transport reports every request it rejects through transport.onerror, and that error reaches Sentry twice:

  1. Sentry's MCP server integration (@sentry/core wrapTransportError) captures every onerror call as an unhandled auto.ai.mcp_server / error_type: transport exception. This is the event we see.
  2. Our server.server.onerror then sends the same error to logIssue. The SDK skips that capture because the error was already captured, but it is still an error-level log and an issue in any path the integration doesn't wrap.

So the hosted MCP turns 4xx client mistakes into high-priority issues, which the repo's 4xx/5xx policy forbids.

Evidence (all 965 events in the issue):

  • 518 come from Go-http-client/2.0 (one account) sending notifications/initialized with no Accept header. ~280 come from Devin-CLI (Windsurf / Devin) sending initialize with Accept: application/json. The rest are node/curl sending */* and hand-written curl requests.
  • The issue also groups other transport rejections with the same stack: Bad Request: Unsupported protocol version (400) and Unsupported Media Type (415). Sibling issues MCP-SERVER-G4R and MCP-SERVER-GM8 (same 406), and MCP-SERVER-GFD, MCP-SERVER-G4W, and MCP-SERVER-G55 (SyntaxError from JSON.parse of the body, 400), are the same class.
  • In the last 90 days every auto.ai.mcp_server transport error in the project was one of these 4xx rejections. No server fault came through this path.
  • No legitimate client is meaningfully broken. Over 14 days, spans show Devin-CLI with about 46k 200s and about 300 406s, Go-http-client with about 12M 200s and about 2.4k 406s, and node with about 6M 200s and 57 406s. Each rejection is a specific probe or a notification. The client keeps working.

Change:

  • isTransportClientRejection in telem/sentry.ts names the rejection rule once. The SDK starts each 4xx rejection message with its HTTP reason phrase (Not Acceptable:, Unsupported Media Type:, Payload Too Large:, Bad Request:, Invalid Request:), and a SyntaxError is a body that fails JSON.parse.
  • sentryBeforeSend drops an event only when it has the integration's transport mechanism (auto.ai.mcp_server + error_type: transport) and the exception matches that rule. Other transport errors, and the same messages from other mechanisms, are still reported.
  • server.onerror logs these rejections with logWarn and still uses logIssue for everything else.
  • The rejections stay visible: app.server.response already counts each /mcp response by status code and app.client.family, and the warning log keeps the message.

Not changed, on purpose: I did not make the server accept */* or a missing Accept. The Streamable HTTP spec (2025-11-25, Sending Messages to the Server) says the client MUST list both application/json and text/event-stream. The traffic data shows no client that depends on that leniency. Under RFC 9110, */* arguably should match, so if we want that leniency it belongs in the MCP TypeScript SDK's substring check, not in a local Accept rewrite.

Related, out of scope: MCP-SERVER-F1J (JsonRpcError_-32603, 627 events) is also client input. An initialize without clientInfo.version fails SDK validation, and the SDK reports it as an internal error (-32603), so the integration captures it as a protocol error. It needs a separate fix.

via @betegon.

--

View Session [Sentry]

The MCP SDK's Streamable HTTP transport answers malformed requests
(missing Accept media type, wrong Content-Type, unparseable body,
unsupported protocol version) with a 4xx and reports each one through
transport.onerror. Sentry's MCP server integration captures every
onerror call as an unhandled error, and server.onerror sent it to
logIssue as well, so client mistakes became high-priority issues.

Classify these rejections once, drop the integration's copy in
sentryBeforeSend, and log them as warnings in server.onerror. Other
transport errors still create issues, and app.server.response keeps
counting the 4xx responses by client family.

Fixes MCP-SERVER-GFB

Co-Authored-By: bete <28983162+betegon@users.noreply.github.com>
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentry-local Ready Ready Preview Nov 16, 2026 1:26pm UTC

Request Review

Comment on lines +251 to +253
const transport = new WebStandardStreamableHTTPServerTransport({
sessionIdGenerator: undefined,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High severity and reachable issue identified in your code:
Line 251 has a potentially vulnerable usage of @modelcontextprotocol/server, possibly introducing a high severity vulnerability.

ℹ️ Why this is reachable

A reachable issue is a possible security risk because your project actually executes the vulnerable code. This issue is reachable because your code calls vulnerable code in this version of @modelcontextprotocol/server.
Affected versions of @modelcontextprotocol/hono, @modelcontextprotocol/node, @modelcontextprotocol/sdk, and @modelcontextprotocol/server are vulnerable to Allocation of Resources Without Limits or Throttling. The MCP TypeScript SDK Streamable HTTP server transports and HTTP handlers (StreamableHTTPServerTransport, WebStandardStreamableHTTPServerTransport, NodeStreamableHTTPServerTransport, createMcpHandler, isLegacyRequest, legacyStatelessFallback, toNodeHandler/toWebRequest, createMcpHonoApp) read POST request bodies without a size limit and dispatch JSON-RPC batches of unbounded length. An unauthenticated remote client can exhaust server memory with an oversized body or block other clients with a very long batch, causing denial of service.

References: GHSA

To resolve this comment:
Upgrade this dependency to at least version 2.1.0 at pnpm-lock.yaml.

💬 Ignore this finding

To ignore this, reply with:

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

You can view more details on this finding in the Semgrep AppSec Platform here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context for a maintainer to triage this (I'm not dismissing it): the flagged line is test-only code in packages/mcp-core/src/server.test.ts. That package resolves @modelcontextprotocol/server from the catalog to 2.4.0 (pnpm-lock.yaml importers), which is above the fixed 2.1.0. The @modelcontextprotocol/server@2.0.0 lockfile entry the finding points to is a transitive dependency of @mastra/core, already on main, and this PR doesn't change the lockfile. Bumping or overriding that transitive copy would be a separate dependency change, so I've left it out of this PR.

…ent-rejections

# Conflicts:
#	packages/mcp-core/src/server.test.ts

This branch was successfully deployed

1 active deployment
Preview — 50decd74 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant